package com.juitar.base.fingering;

import com.juitar.base.Fingering;


/**
 * @author SKopylov
 */
public class FingeringFilter implements IFingeringFilter {

	private int _length;

	private int _firstFret;

	private int _inversion;

	private boolean _allowMuted;

	public FingeringFilter(int fingeringLength, int fingeringFirstFret,
			int inversion, boolean useMuted) {
		_length = fingeringLength;
		_firstFret = fingeringFirstFret;
		_inversion = inversion;
		_allowMuted = useMuted;
	}

	/* (non-Javadoc)
     * @see com.juitar.base.fingering.IFingeringFilter#accept(com.juitar.base.Fingering)
     */
	public boolean accept(Fingering fing) {

		if (fing.length() > _length) {
			return false;
		}

		if (_firstFret > 0 && _firstFret != fing.getFirstFret()) {
			return false;
		}

		if (_inversion > 0 && _inversion != fing.getInversion()) {
			return false;
		}

		if (!_allowMuted) {
			if (fing.numOfMutedStrings() > 0) {
				return false;
			}
		}

		return true;
	}
}
